package com.edu.api.common.web.base.http;

import lombok.Data;

/**
 * @author: lugao.zhang
 * @date: 2024/6/7 22:15
 */
@Data
public class Result<T> {

	public static final String SUCCESS_MESSAGE = "success";
	public static final String FAIL_MESSAGE = "fail";
	public static final Integer SUCCESS_CODE = 200;
	public static final Integer ERROR_CODE = 500;

	private long timestamp = System.currentTimeMillis();
	private int code;
	private String message;
	private T data;

	public Result() {
		this.code = SUCCESS_CODE;
		this.message = SUCCESS_MESSAGE;
	}

	public static <T> Result<T> success() {
		return new Result<>();
	}

	public static <T> Result<T> success(T data) {
		Result<T> result = new Result<>();
		result.setData(data);
		return result;
	}

	public static <T> Result<T> fail() {
		Result<T> result = new Result<>();
		result.setCode(ERROR_CODE);
		result.setMessage(FAIL_MESSAGE);
		return result;
	}

	public static <T> Result<T> fail(String message) {
		Result<T> result = new Result<>();
		result.setCode(ERROR_CODE);
		result.setMessage(message);
		return result;
	}

	public static <T> Result<T> fail(int code, String message) {
		Result<T> result = new Result<>();
		result.setCode(code);
		result.setMessage(message);
		return result;
	}

}